package com.security.securityproject.controller;

import com.security.securityproject.entity.SysUser;
import com.security.securityproject.service.SysUserService;
import com.security.securityproject.service.serviceImpl.UserDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.lang.model.element.VariableElement;
import java.util.List;

/**
 * @author huangkf
 * @version 1.0
 * @date 2022/11/29:17:38
 * @description 用户控制类
 */


//@RestController
//@RequestMapping("user")

@Controller
public class SysUserController {


    @Autowired
    private SysUserService sysUserService;


    @Autowired
    private UserDetailsServiceImpl userDetailsService;


//    @RequestMapping("all")
//    public List<SysUser> getUsers() {
//        List<SysUser> sysUsers = sysUserService.findSysUsers();
//
//        return sysUsers;
//    }
//
//
//    @PostMapping("byUserName")
//    public SysUser getByUserName(String userName) {
//        SysUser userInfo = sysUserService.getByUserName(userName);
//
//        return userInfo;
//
//    }
//
//
//    @PostMapping("byIdAndUserName")
//    public SysUser getByIdUserName(String userName, Integer id) {
//        SysUser byIdAndName = sysUserService.findByIdAndName(id, userName);
//        return byIdAndName;
//    }
//
//    @PostMapping("/logins")
//    public Object modelLogin(String name) {
//        System.out.println("---------------------");
//        UserDetails userDetails = userDetailsService.loadUserByUsername(name);
//
//
//        System.out.println("hello");
//        return "userDetails";
//    }

    @RequestMapping("login")
    public String login(){
        return "login";
    }

   // @Secured("ROLE_超级管理员") //针对于启动类上的注解 @EnableGlobalMethodSecurity(securedEnabled = true)
   // @PreAuthorize("hasRole('超级管理员')")    //SecurityExpressionRoot
    @PreAuthorize("hasAuthority('demo:delete')")
    @RequestMapping("loginSuccess")
    public String loginSuccess(){
        return "index";
    }

    @RequestMapping("loginfail")
    public String loginFail(){
        return "fail";
    }

    //测试没配置权限
    @RequestMapping("loginfaila")
    public String loginFaila(){
        return "faila";
    }


    @RequestMapping("adc")
    public String adc(){
        return "adc";
    }
}
